import axios from 'axios';
import { ElMessage } from 'element-plus'
import router from '../router'
// const router = useRouter();
const request = axios.create({
    //基础配置信息
    // timeout: 10000,//请求超时
    baseURL: 'http://121.89.205.189:3000/admin/',//固定单词，公共地址部分
    // baseURL: 'http://120.46.204.16:8008/admin',
    headers: {
        'Content-Type': 'application/json;chartset=utf-8'
    }
})
// 响应拦截
request.interceptors.response.use(response => {
    if (response.data.code !== '200') {
        if (response.data.code === '10119'){
        router.push('/');
        ElMessage.error('登录过期');
        }
    }
    return response
})

//请求拦截
request.interceptors.request.use(request => {
    request.headers['token'] = localStorage.getItem('token');
    return request
})
export default request